package com.sdry.approval.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdry.approval.entity.LeaveRequest;
import com.sdry.approval.entity.PatchCardRequest;
import com.sdry.approval.service.PatchCardRequestService;
import com.sdry.common.BaseController;
import com.sdry.system.entity.SysUser;
import com.sdry.system.service.UserService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: info_sdry
 * @description: 补卡申请
 * @author: cb
 * @create: 2020-02-21 17:00
 **/
@Controller
@RequestMapping(value = "/patchCardRequest")
public class PatchCardRequestController extends BaseController {

    @Autowired
    private PatchCardRequestService patchCardRequestService;

    @Autowired
    private UserService userService;

    /**
     * 补卡展示
     * @return
     */
    @RequestMapping(value = "/apply")
    public String repair(Model model) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_flag",0L).eq("log_on",0L).select("user_id","real_name");
        List<SysUser> sysUserList = userService.list(queryWrapper);
        model.addAttribute("sysUserList",sysUserList);
        return "/approval/apply/patchCard";
    }

    /**
     * 添加
     * @param patchCardRequest 申请对象
     * @return
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public boolean add(PatchCardRequest patchCardRequest, @RequestParam("userId[]") String[] userId) {
        logger.info("补卡申请添加成功 leaveRequest = {}"+ JSONObject.fromObject(patchCardRequest));
        return  patchCardRequestService.add(patchCardRequest,userId);
    }



}
